home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / ACL / Animation Class Library / Headers / Anim.h next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  7.7 KB  |  242 lines  |  [TEXT/MPCC]

  1.  
  2. /********************************************
  3.  **** Animation Class Library V1.0 © 1994 Yves Schmid & Alia Development
  4.  ****
  5.  **** Anim.h
  6.  ****
  7.  **** Created:      13 May 1994
  8.  **** Modified:     02 September 1994
  9.  **** Version:      0
  10.  **** Compatible:   C++, Mac System 7
  11.  ****
  12.  **** Description:  Definitions for the Anim class.
  13.  ****
  14.  ****                Anim is a child class of the AnimCObject class.
  15.  ****
  16.  *******************/
  17.  
  18.  
  19. #ifndef Anim_H
  20. #define Anim_H
  21.  
  22.  
  23. #include "AnimCObject.h"
  24. #include "AnimFrame.h"
  25.  
  26. struct AnimFrameDef;
  27. class AnimBase;
  28.  
  29. class Anim: public AnimCObject
  30. {
  31.  
  32.     //***********************************************************
  33.     //.............. P U B L I C   M E T H O D S.................
  34.  
  35.     public:
  36.  
  37.     // Anim should be linked to a supervisor (AnimBase, Anim, AnimMask,...)
  38.  
  39.     Anim(AnimSupervisor *base);
  40.     Anim(AnimSupervisor *base, AnimFrameDef *def);    // An array of AnimFrameDef
  41.  
  42.     Anim(AnimSupervisor *base, AnimGfx *gfx);        // Builds a one frame object
  43.     Anim(AnimSupervisor *base, long resID);
  44.  
  45.     
  46.     ~Anim(void);
  47.  
  48.     
  49.     void findmaxsize(short *width, short *height) const; // Finds the maximum pixels size of the
  50.                                                          // current sequence. Checks all frames.
  51.                                                          // You can pass NULL pointers.     
  52.  
  53.     void findmaxsize(long sequence, short *width, short *height) const; 
  54.                                                     // Same method but you can
  55.                                                     // specify the sequence.
  56.  
  57.     void findmaxsizeseq(short *width, short *height) const; 
  58.                                                     // Same method but does the job
  59.                                                     // for all sequences.
  60.  
  61.  
  62.     void findcursize(short *width, short *height);          // Finds the maximum pixels size of the
  63.                                                          // current frame. If there is no
  64.                                                          // current frame returns 0.
  65.                                                          // You can pass NULL pointers.     
  66.  
  67.     void findcurrect(Rect *rect); // Finds the visual rect of the current frame.
  68.  
  69.  
  70.     void arrangeframes(long sequence,             // Arranges the frames
  71.                        short horizontalcmd,        // of a sequence. This method centers
  72.                        short verticalcmd,        // or aligns frames on x and/or y axix.
  73.                        short baseoffsetx =0,    // See arrange cmds.
  74.                        short baseoffsety =0);    // Base offsets may be used to
  75.                                                 // specify a global offset relative
  76.                                                 // the Anim position.
  77.  
  78.     void arrangeframesall(short horizontalcmd,    // Same as "arrangeframes" but
  79.                        short verticalcmd,        // for all sequences.
  80.                        short baseoffsetx =0,
  81.                        short baseoffsety =0);
  82.  
  83.     void arrange_moveframeoffsets(long sequence,        // Adds a value to all frames
  84.                               short addoffsetx,            // offsets for a specified
  85.                                  short addoffsety);        // sequence.
  86.  
  87.     void arrange_moveframeoffsetsall(short addoffsetx,  // Same as "arrange_moveframeoffsets" 
  88.                                           short addoffsety);    // but for all sequences.
  89.  
  90.  
  91.     // Does for each frames: adds or substracts the size of the frame to the offset of the
  92.     // frame. Horizontal and vertical should be equal to -1, 0 or 1. If -1 substracts, if
  93.     // 0 does nothing, if 1 adds.
  94.  
  95.     void arrange_movehandlepoint(long sequence,
  96.                                  short horizontal, short vertical);
  97.  
  98.     // Same as "arrange_movehandlepoint" but for all sequences
  99.     void arrange_movehandlepointall(short horizontal, short vertical);
  100.  
  101.  
  102.     // Sets/gets animation flags. See anim flags. 
  103.     inline unsigned short getanimflags(void) const {return animflags;}
  104.     inline void setanimflags(const unsigned short anfl) {animflags = anfl;}
  105.  
  106.  
  107.     // Changes the state of the frame counter
  108.  
  109.     inline void clearcounter(void) {framecounter = 0;}
  110.     inline short getcounter(void) const {return framecounter;}
  111.     inline void setcounter(const short c) {framecounter = c;}
  112.     
  113.         
  114.     void setsequence(long a, Boolean resetframepos =TRUE);    // Sets the current sequence
  115.     void setnsequences(long n);    // Specifies the number of sequences
  116.     
  117.     inline long getnsequences(void) const {return getnentry()-1;}    // Number of seq.
  118.     inline long getcurrentsequence(void) const {return currentsequence-1;}    // Current seq.
  119.                                                                            // number
  120.  
  121.     void addframe(short sequence, AnimFrame *frame);     // Adds an AnimFrame to a sequence
  122.     void addframe(short sequence, AnimFrame *frame, long pos); // Allows you to specify
  123.                                                               // where the frame should be
  124.                                                              // inserted      
  125.  
  126.     virtual AnimFrame *newframe(short sequence);            // Creates a frame, adds it and returns it
  127.     virtual AnimFrame *newframe(short sequence, long pos);    // Allows you to specify
  128.                                                             // where the frame should be
  129.                                                             // inserted
  130.  
  131.     AnimFrame *getcurrentframe(void);               // Returns current frame or NULL if there is no frame
  132.     long getcurrentframepos(void);                  // Returns current frame position or ~0 if there is no frame
  133.     void setcurrentframe(long framepos);         // Sets the current frame
  134.     inline CoreList *getframelist(long seq) {return getentry(seq+1);}  // Returns the
  135.                                                                       // list of frames    
  136.                                                                      // for a specified
  137.                                                                     // sequence                                    
  138.  
  139.     inline AnimFrame *getfirstframe(long seq) {return (AnimFrame*)getentry(seq+1)->getfirst();}  
  140.                                                                     // Returns the first
  141.                                                                    // frame of a specified    
  142.                                                                   // entry.
  143.  
  144.     //***********************************************************
  145.  
  146.     //..........................................................
  147.     // You should not call the following methods!
  148.  
  149.  
  150.     virtual void getcollisionmask(BitMap **b, unsigned long **lmask, Rect *);
  151.     virtual Boolean mustbemasked(void) const;
  152.  
  153.     Boolean draw(short basex =0, short basey =0);
  154.     
  155.     //..........................................................
  156.  
  157.  
  158.     protected:
  159.  
  160.     long        currentsequence;
  161.  
  162.  
  163.     virtual void initonecontrol(AnimControl *);    
  164.                                                         
  165.                                                                     
  166.     virtual Boolean processonecontrol(AnimControl *);    
  167.  
  168.     virtual void receivecmd(long cmd, void *info);
  169.  
  170.     void process_submasking(AnimBase *base, Rect *maskrect);
  171.  
  172.     private:
  173.     
  174.     short        framecounter;            
  175.     AnimFrame    *currentframe;            
  176.  
  177.     long        cwaitnframe;
  178.     AnimFrame    *cwframe;    
  179.  
  180.     unsigned short animflags;    
  181.  
  182.     void sortsubanims(void);
  183.  
  184.         
  185. };
  186.  
  187. //................................
  188. // Animation flags
  189.  
  190. #define    ANF_REVERSE        (1<<0)        // If you set this flag, animation will be
  191.                                     // reversed. (last frame -> first frame).
  192.  
  193. #define ANF_PINGPONG    (1<<1)        // When the animation reachs the last frame
  194.                                     // the ANF_REVERSE flag is setted and when
  195.                                     // the first frame is reached the ANF_REVERSE
  196.                                     // is unsetted. This is ping-pong animation.
  197.  
  198.  
  199. //................................
  200. // Cmds for the "arrangeframes" method
  201.  
  202.  
  203. #define arcmd_null             0            // Does not touch the frame position
  204. #define arcmd_center         1            // Centers frames
  205. #define arcmd_alignleft     2            // Aligns frames on left/top
  206. #define arcmd_aligntop        2
  207. #define arcmd_alignright     3            // Aligns frames on right/bottom
  208. #define arcmd_alignbottom    3
  209.  
  210. //................................
  211. // You can construct a full animation object simply by passing an array
  212. // of AnimFrameDef.
  213. //
  214. // For example:
  215. //
  216. //                             ResID  AnimGfx    count    offsets    command    
  217. // AnimFrameDef myanim[] = {{100,    NULL,    1,        0,0,    afcmd_frame},        // Adds frames
  218. //                            {100,    NULL,    1,        0,0,    afcmd_frame},
  219. //                            {100,    NULL,    1,        0,0,    afcmd_frame},
  220. //                            {100,    NULL,    1,        0,0,    afcmd_endsequence},    // The next frame starts
  221. //                            {100,    NULL,    1,        0,0,    afcmd_frame},        // a new sequence
  222. //                            {100,    NULL,    1,        0,0,    afcmd_frame},
  223. //                            {100,    NULL,    1,        0,0,    afcmd_endanim}};    // End of animation
  224.  
  225.  
  226. struct AnimFrameDef
  227. {
  228.     long        pictRESID;            // The pict resource ID or...
  229.     AnimGfx        *animgfx;            // an AnimGfx pointer
  230.     short        changecounter;        // When must the anim go to next frame
  231.     short        offsetx,offsety;    // Offset of the object (from the animation origin)
  232.     short        cmd;                // A command
  233. };
  234.  
  235.  
  236. const short afcmd_frame = 1;            // a new frame
  237. const short afcmd_endsequence = 2;        // the next frame starts a new sequence
  238. const short afcmd_endanim = 0;            // this is the last frame of the animation
  239.  
  240. #endif
  241.  
  242.